//////////////////////////////////////////////////////////////////////////////////
//
//	AvaMods BotMod2
//		- Version 1.0
//		- 05.20.2008
//		- diamond-optic
//
//////////////////////////////////////////////////////////////////////////////////
//
// Information:
//
//	A much more basic & simple version of the original botmod:
//		- Clears bot's score on join
//		- Does not allow bots to be sniper/deployable classes
//
//////////////////////////////////////////////////////////////////////////////////
//
// Changelog:
//
//	- 06.05.2007 Version 0.1beta
//		added random class changes
//
// 	- 06.07.2007 Version 0.2beta
//		changed way brits change class (AvaMods Player Models plugin will now catch it)
//
// 	- 11.30.2007 Version 1.0
//		Initial Public Release
//
// 	- 04.03.2008 Version 1.0 (re-release)
//		Public CVAR
//
// 	- 05.20.2008 Version 1.1 (re-release)
//		Changed respawn hook over to PStatus
//
//////////////////////////////////////////////////////////////////////////////////



#include <amxmodx>
#include <dodfun>
#include <dodx>

new VERSION[] = "1.1"
new SVERSION[] = "v1.1 - by diamond-optic (www.AvaMods.com)"

public plugin_init()
{
	register_plugin("AvaMods BotMod2",VERSION,"diamond-optic")
	register_cvar("avamods_botmod2_stats",SVERSION,FCVAR_SERVER|FCVAR_SPONLY)
	
	//Temp fix for spawning
	register_message(get_user_msgid("PStatus"),"msg_PStatus")
}

////////////////////////////////////////////////////
// Temp fix for spawn hook
//
public msg_PStatus(msgid,msgdest,id)
{
	if(msgdest == 2 && !id)
		{
		new player = get_msg_arg_int(1)
		new status = get_msg_arg_int(2)
		
		if(is_user_connected(player) && status == 0)
			set_task(Float:0.1,"player_spawn",player)
		}
}

public client_putinserver(id)
{
	if(is_user_bot(id) && is_user_connected(id))
		{
		set_task(0.3, "change_class", id)
		
		set_task(0.5, "bot_score", id)
		}
}

public client_disconnect(id)
	if(is_user_bot(id) && task_exists(id))
		remove_task(id)

public player_spawn(id)
	if(is_user_bot(id) && random_num(0,1) == 1)
		change_class(id)	

public change_class(id)
{
	if(is_user_bot(id) && is_user_connected(id))
		{
		new team = get_user_team(id)
			
		if(team == 1 && dod_get_map_info(MI_ALLIES_TEAM) == 1)	//allies & brits?
			{
			switch(random_num(0, 1))
				{
				case 0: engclient_cmd(id,"cls_enfield") //dod_set_user_class(id, DODC_ENFIELD)
				case 1: engclient_cmd(id,"cls_sten")	//dod_set_user_class(id, DODC_STEN)
				}
			}
		else if(team == 1)	//allies
			{
			switch(random_num(0, 3))
				{
				case 0:	dod_set_user_class(id, DODC_GARAND)
				case 1:	dod_set_user_class(id, DODC_CARBINE)
				case 2:	dod_set_user_class(id, DODC_GREASE)
				case 3:	dod_set_user_class(id, DODC_THOMPSON)
				}
			}
		else if(team == 2)	//axis
			{
			switch(random_num(0, 3))
				{
				case 0:	dod_set_user_class(id, DODC_KAR)
				case 1:	dod_set_user_class(id, DODC_K43)
				case 2:	dod_set_user_class(id, DODC_MP40)
				case 3:	dod_set_user_class(id, DODC_MP44)
				}
			}
		}
}

public bot_score(id)
{
	if(is_user_connected(id) && is_user_bot(id))
		{
		dod_set_user_kills(id, 0, 1)
		dod_set_user_score(id, 0, 1)
		dod_set_pl_deaths(id, 0, 1)
		}
}
